package com.imooc.common.thread;

class MyThread extends Thread{
    private int ticketsCount =5;
    private String name; // 线程的名字
    public MyThread(String name){
        this.name = name;
    }

    @Override
    public void run() {
        while (ticketsCount>0){
            ticketsCount--;
            System.out.println(name+"买了一张票,剩余票数为:"+ticketsCount);
        }

    }
}

public class TircketsThread {

    public static void main(String[] args) {
        // 创建三个线程,模拟三个窗口卖票
        MyThread mt1 = new MyThread("窗口1");
        MyThread mt2 = new MyThread("窗口2");
        MyThread mt3 = new MyThread("窗口3");
        // 启动这三个线程,也即是窗口,开始卖票
        mt1.start();
        mt2.start();
        mt3.start();


    }



}
